<script type="text/javascript" src="/Public/js/jquery.form.min.js"></script>
<script language="javascript" type="text/javascript" src="__PUBLIC__/js/My97DatePicker/WdatePicker.js"></script>
<div class="form">
  <form method='post' id="form_do" name="form_do" action="{:U(MODULE_NAME.'/Product/actadd')}">
    <dl>
      <dt>活动名称：</dt>
      <dd>
        <input type="text" name="title" class="inp_large" maxlength="20"  /><font color="red">(最长20个字符)</font>
      </dd>
    </dl>
    <dl>
      <dt>预售期：</dt>
      <dd>
      <input  type="text" class="Wdate input-s" onClick="WdatePicker()" name="presellDateStart"  readonly="readonly" />
      -
      <input  type="text" class="Wdate input-s" onClick="WdatePicker()" name="presellDateEnd"  readonly="readonly" />
      <input type="checkbox" name="presellDateFullPrice" value="1">预售期可全价购买
      </dd>
    </dl>
    <dl>
      <dt>尾款期：</dt>
      <dd>
      <input  type="text" class="Wdate input-s" onClick="WdatePicker()" name="paymentDateStart"  readonly="readonly" />
      -
      <input  type="text" class="Wdate input-s" onClick="WdatePicker()" name="paymentDateEnd"  readonly="readonly" />
      <input type="checkbox" name="presellDatePaymentPrice" value="1">预售期可付尾款
      </dd>
    </dl>
    <dl>
      <dt>预约期：</dt>
      <dd>
      <input  type="text" class="Wdate input-s" onClick="WdatePicker()" name="appointmentDateStart"  readonly="readonly" />
      -
      <input  type="text" class="Wdate input-s" onClick="WdatePicker()" name="appointmentDateEnd"  readonly="readonly" />
      </dd>
    </dl>
    <dl>
      <dt> 活动图片：</dt>
      <dd>
        <div style="width: 120px; height: 120px;  border: 1px #CCC solid;   position: relative;   overflow: hidden; text-align: center;vertical-align: middle;cursor: pointer;">
          <input type="file" name="filedata" id="actPic" onChange="uploadPic(this,'actPic')" style="width:120px; height: 120px; position: absolute; right: 0;left: 0;bottom: 0;top: 0;margin: auto;opacity: 0;z-index: 9999">
          <div  class="fileupload" style="  position: absolute;width: 120px;height: auto;right: 0;left: 0;bottom: 0;top: 0;margin: auto;">
          </div>
        </div>
      </dd>
    </dl>
    <div class="form_b" style="width: 300px; margin-left: 110px;">
      <input type="button" class="button-green" onclick="submitDo()" value="保 存">
      &nbsp;
      <input type="button" onclick="goUrl('{:U('/Home/Product/actlist')}')" class="button-return" value="返回产品列表">
    </div>
  </form>
</div>
<script type="text/javascript">
$(function() {

  wrapForm('actPic','actPic');

});
/**
 * [wrapForm description]
 * @param  {[type]} id   [description]
 * @param  {[type]} type [description]
 * @return {[type]}      [description]
 */
function wrapForm (id,type)
{
    $("#"+id).wrap("<form class='uploadImg' action='/Home/Public/uploadPic/fileType/Img/type/"+type+"/corp/1.html' method='post' enctype='multipart/form-data'></form>");
}
  /**
   * [uploadPic description]
   * @param  {[type]} obj [description]
   * @return {[type]}     [description]
   */
  function uploadPic(obj,name)
  {
      if($(obj).val() == "") return;

      $(obj).parent().ajaxSubmit({
          dataType:  'json',
          beforeSend: function() {
            $(obj).parent().parent().find('.fileupload').empty();
            $(obj).parent().parent().find('.fileupload').html("正在上传中...");
          },
          success: function(data) {

            if(data.state == 'SUCCESS')
            {
                $(obj).parent().parent().find('.fileupload').empty();
                $(obj).parent().parent().find('.fileupload').html("<img src='http://www.tripvip.cn"+data.url+"' width='120' height='120'>");
                $(obj).parent().parent().find('.fileupload').append("<input type='hidden' name='"+name+"' class='"+name+"' value='"+data.url+"'>");

            }
            else
            {
                $(obj).parent().parent().find('.fileupload').html(data.msg);
            }
        },
        error:function(xhr){
          $(obj).parent().parent().find('.fileupload').html('上传失败!');
          $(obj).parent().parent().find('.fileupload').html(xhr);
        }
      });
  }

/**
 * [submitDo description]
 * @return {[type]} [description]
 */
function submitDo() 
{ 
  if($('input[name="title"]').length > 0)
  {
    if($('input[name="title"]').val().length > 0)
    {
      $('input[name="title"]').css('border','1px green solid');
      $('#form_do').submit();
    }
    else
    {
      $('input[name="title"]').css('border','1px red solid');
    }
  }
  else
  {
    $('#form_do').submit();
  }

}


</script>